package com.wwj.study.singleton.lazy;

import java.lang.reflect.Constructor;
import java.util.concurrent.CountDownLatch;

/**
 * Created by lenovo on 2018/11/15.
 */
public class LazyFiveTest {

    public static void main(String[] args) {


        try {
            //获取类
            Class<?> aClass=Class.forName("com.wwj.study.singleton.lazy.LazyFive");
            //反射方式获取类的私有构造方法
            Constructor c=aClass.getDeclaredConstructor(null);
            //强制访问
            c.setAccessible(true);
            Object obj1= c.newInstance();
            //第一次获取对象
            Object obj2= c.newInstance();
            System.out.println(obj1);
            //第二次获取对象
            System.out.println(obj2);

        } catch (Exception e) {
            e.printStackTrace();
        }


        long start = System.currentTimeMillis();
        System.out.println("开始时间：" + start);
        int count = 100;
        final CountDownLatch countDownLatch = new CountDownLatch(count);

        for (int i = 0; i < count; i++) {
            new Thread() {
                @Override
                public void run() {
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }




                }
            }.start();

            countDownLatch.countDown();
        }

        long end = System.currentTimeMillis();
        System.out.println("结束时间：" + end);

        System.out.println("耗时：" + (end - start));
    }
}
